//
//  STBasicVC.swift
//  Demo-04-TabBar的尝试
//
//  Created by 苏统世 on 16/5/9.
//  Copyright © 2016年 SuTon. All rights reserved.
//

import UIKit

// MARK: - === UITabBarController ===
class STTabBarVC: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let centerButton=STCustomTabBar()
        centerButton.centerButtonBlock={
            STPrint(items: "点击了中间按钮")
            
            if STUserAccountViewModel.shareManager.isUserLogin {
                
                let navVC = STNavigationVC(rootViewController: STPushVC())
                
                self.presentViewController(navVC, animated: true, completion: nil)
                
            }else{
                
                STPrint(items: "还二米登陆")
            }
        }
        setValue(centerButton, forKey: "tabBar")
        
        setChildVC()
        
    }
    
// MARK: - === 添加子控制器 ===
    func setChildVC(){
        addChildVC(STHomeVC(), vcTitle: "首页", normolImage: UIImage(named: "tabbar_home")!, SelectImage: UIImage(named: "tabbar_home_selected")!)
        
        addChildVC(STMessagesVC(), vcTitle: "消息", normolImage: UIImage(named: "tabbar_message_center")!, SelectImage: UIImage(named: "tabbar_message_center_selected")!)
        
        addChildVC(STSearchVC(), vcTitle: "发现", normolImage: UIImage(named: "tabbar_discover")!, SelectImage: UIImage(named: "tabbar_discover_selected")!)
        
        addChildVC(STMeVC(), vcTitle: "我", normolImage: UIImage(named: "tabbar_profile")!, SelectImage: UIImage(named: "tabbar_profile_selected")!)
    }
    
    func addChildVC(childVC: UIViewController,vcTitle title: String,normolImage norImage: UIImage,SelectImage selImage: UIImage) {
        let navVC = STNavigationVC(rootViewController: childVC)
        childVC.title = title
        // 不渲染图片
        childVC.tabBarItem.image = norImage.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childVC.tabBarItem.selectedImage = selImage.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        childVC.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14),NSForegroundColorAttributeName:UIColor.blackColor()], forState: UIControlState.Normal)
        childVC.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14),NSForegroundColorAttributeName:UIColor.redColor()], forState: UIControlState.Selected)
        self.addChildViewController(navVC)
    }
    
// MARK: - === UITabBarController 内存警告处理 ===
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
       
    }
}
// MARK: - === UINavigationController ===
class STNavigationVC: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        

    }
}
